package com.htgraph.flash;

/**
 * Created by IntelliJ IDEA.
 *
 * @author Dong Shufeng
 *         Date: 2010-11-25
 */
public class FlashThread extends Thread {
    private Flasher flasher;
    private boolean stop = false;
    private long flashPeriod = 800;
    private boolean isPause = false;

    public FlashThread() {
    }

    public FlashThread(Flasher flasher) {
        this.flasher = flasher;
    }

    public FlashThread(Flasher flasher, long period) {
        this.flasher = flasher;
        this.flashPeriod = period;
    }

    public void run() {
        while (!stop) {
            if (!isPause) {
                try {
                    if (flasher != null && !flasher.getEditState()) {
                        flasher.flash();
                        sleep(flashPeriod);
                    } else
                        sleep(10);
                } catch (InterruptedException e) {
                    System.out.println(e);
                }
            }else
                try {
                    sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
        }
        //System.out.println("Flash thread stopped.");
    }

    public Flasher getFlasher() {
        return flasher;
    }

    public void setFlasher(Flasher flasher) {
        this.flasher = flasher;
    }

    public boolean isStop() {
        return stop;
    }

    public void setStop(boolean stop) {
        this.stop = stop;
    }

    public long getFlashPeriod() {
        return flashPeriod;
    }

    public void setFlashPeriod(long flashPeriod) {
        this.flashPeriod = flashPeriod;
    }

    public boolean isPause() {
        return isPause;
    }

    public void setPause(boolean pause) {
        isPause = pause;
    }
}
